// pageLevelData[]
// pageData[]
// docLevelData

var pdeApp = new PDEApp();
var pdDoc = new PDDoc();
var gContainerMgr = new ContainerManager();
var dataMgr = new DataMgr();
var fontLoader = new FontLoader();
var pageCount = pageData.length;
fontLoader.standFont = "file:///D:/Foxit/GreateLadder/CmnFonts/";
fontLoader.webFont = "webfont.js";

function InitOnlineEditor(){
	gContainerMgr.InitContainers();
	addEventListener("resize", ContainerManager.prototype.OnResize, false);
	pdDoc.ParseJsonToDoc(docLevelData);
	pdDoc.SetCountPages(pageCount);
	var tempPage = null;
	for (var i = 0; i < pageCount; i++){
		pdDoc.AddPageLevelData(i, pageLevelData[i]);
		tempPage = pdDoc.GetPageByIndex(i);
		tempPage.AddPageObjects(pageData[i]);
		
	}
	
	var pdPage = pdDoc.GetPageByIndex(0);
	if (null == pdPage) return;
	fontLoader.callback = RenderPage;
	if (pdPage.pdPageObjects.bFinishLoadImgs || pdPage.pdPageObjects.imgObjCount === 0) {
		fontLoader.LoadFamiliesByPage();
	}
	else {
		pdPage.pdPageObjects.callback = fontLoader.LoadFamiliesByPage;
		pdPage.pdPageObjects.caller = fontLoader;	
	}
	
}

function RenderPage(){
	document.title = pdDoc.docTitle;
	pdeApp.OpenPDDocument(document, pdDoc, gContainerMgr.clientDiv);
	pdeApp.docEx.editorViewer.DrawPages();
	
}


$(document).ready(InitOnlineEditor);
